﻿using System;
using System.Collections.Generic;
using KKSG;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	// Token: 0x020016E7 RID: 5863
	internal class GVGBattleMemberBase : IGVGBattleMember
	{
		// Token: 0x0600F1E1 RID: 61921 RVA: 0x00358854 File Offset: 0x00356A54
		public void Setup(GameObject sv, int index)
		{
			this.mIndex = index;
			this._Doc = XDocuments.GetSpecificDocument<XGuildArenaBattleDocument>(XGuildArenaBattleDocument.uuID);
			this._GuildDoc = XDocuments.GetSpecificDocument<XGuildDocument>(XGuildDocument.uuID);
			this.transform = sv.transform;
			this.m_GuildName = (this.transform.Find("Title/Title1").GetComponent("XUILabelSymbol") as IXUILabelSymbol);
			this.m_ScrollView = (this.transform.Find("MemberScrollView").GetComponent("XUIScrollView") as IXUIScrollView);
			this.m_WrapContent = (this.transform.Find("MemberScrollView/MemberList").GetComponent("XUIWrapContent") as IXUIWrapContent);
			this.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.WrapItemUpdateEventHandler));
		}

		// Token: 0x0600F1E2 RID: 61922 RVA: 0x0035891C File Offset: 0x00356B1C
		private void FormatRole(ref List<GmfRole> roles)
		{
			bool flag = roles == null;
			if (flag)
			{
				roles = new List<GmfRole>();
			}
			int battleSignNumber = this._Doc.GetBattleSignNumber();
			bool flag2 = roles.Count < battleSignNumber;
			if (flag2)
			{
				int count = roles.Count;
				for (int i = count; i < battleSignNumber; i++)
				{
					GmfRole gmfRole = new GmfRole();
					gmfRole.rolename = XSingleton<XStringTable>.singleton.GetString("GUILD_ARENA_TAB_PERSON");
					gmfRole.index = i;
					gmfRole.roleID = 0UL;
					gmfRole.profession = 0;
					roles.Add(gmfRole);
				}
			}
		}

		// Token: 0x0600F1E3 RID: 61923 RVA: 0x003589BC File Offset: 0x00356BBC
		public void ReFreshData(GVGBattleInfo battleInfo)
		{
			bool flag = battleInfo.Base == null || battleInfo.Group == null;
			if (!flag)
			{
				bool flag2 = this.mRoles == null;
				if (flag2)
				{
					this.mRoles = new List<GmfRole>();
				}
				this.mRoles.Clear();
				this.mRoles.AddRange(battleInfo.Group);
				this.FormatRole(ref this.mRoles);
				this.isSelfGuild = (this._GuildDoc.bInGuild && this._GuildDoc.BasicData.uid == battleInfo.Base.guildid);
				this.m_WrapContent.SetContentCount(this.mRoles.Count, false);
				this.m_ScrollView.ResetPosition();
				bool flag3 = this._Doc.IsGCF();
				if (flag3)
				{
					this.m_GuildName.InputText = XStringDefineProxy.GetString("CROSS_GVG_GUILDNAME", new object[]
					{
						battleInfo.Base.serverid,
						battleInfo.Base.guildname
					});
				}
				else
				{
					this.m_GuildName.InputText = battleInfo.Base.guildname;
				}
			}
		}

		// Token: 0x0600F1E4 RID: 61924 RVA: 0x00358AE8 File Offset: 0x00356CE8
		private void WrapItemUpdateEventHandler(Transform t, int index)
		{
			bool flag = index < 0 || index >= this.mRoles.Count;
			if (!flag)
			{
				GmfRole gmfRole = this.mRoles[index];
				bool flag2 = gmfRole == null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("XMainClient.UI.GuildArenaBattleMemberPanel.WrapItemUpdateEventHandler is null ", null, null, null, null, null);
				}
				else
				{
					IXUILabel ixuilabel = t.Find("Status/Num").GetComponent("XUILabel") as IXUILabel;
					IXUISprite ixuisprite = t.Find("Status/Battle").GetComponent("XUISprite") as IXUISprite;
					IXUILabel ixuilabel2 = t.Find("Fight").GetComponent("XUILabel") as IXUILabel;
					IXUILabel ixuilabel3 = t.Find("Name").GetComponent("XUILabel") as IXUILabel;
					IXUISprite ixuisprite2 = t.Find("kick").GetComponent("XUISprite") as IXUISprite;
					IXUISprite ixuisprite3 = t.Find("job").GetComponent("XUISprite") as IXUISprite;
					GameObject gameObject = t.Find("icon").gameObject;
					ixuilabel.SetText((index + 1).ToString());
					ixuilabel3.SetText(gmfRole.rolename);
					ixuisprite3.SetAlpha(1f);
					ixuisprite3.SetSprite(XSingleton<XProfessionSkillMgr>.singleton.GetProfIcon(gmfRole.profession));
					ixuisprite2.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnRemove));
					ixuisprite2.ID = gmfRole.roleID;
					bool flag3 = gmfRole.roleID == 0UL;
					if (flag3)
					{
						ixuisprite.gameObject.SetActive(false);
						ixuilabel2.gameObject.SetActive(false);
						ixuisprite2.gameObject.SetActive(false);
						gameObject.SetActive(false);
						ixuilabel.SetVisible(true);
						ixuilabel.SetColor(Color.white);
						ixuilabel3.SetColor(Color.white);
						ixuilabel2.SetColor(Color.white);
						bool flag4 = ixuisprite3 != null;
						if (flag4)
						{
							ixuisprite3.SetAlpha(0f);
						}
					}
					else
					{
						ixuisprite.gameObject.SetActive(true);
						ixuilabel2.gameObject.SetActive(true);
						ixuisprite2.gameObject.SetActive(true);
						gameObject.SetActive(true);
						this.SetupOtherMemberInfo(t, gmfRole);
						bool flag5 = this.isSelfGuild;
						XGuildArenaBattleDocument.GuildArenaSection mArenaSection = this._Doc.mArenaSection;
						if (mArenaSection != XGuildArenaBattleDocument.GuildArenaSection.Prepare)
						{
							if (mArenaSection == XGuildArenaBattleDocument.GuildArenaSection.Battle)
							{
								flag5 &= this.SetMatchFightState(gmfRole, ixuisprite, ixuilabel, ixuilabel3, ixuilabel2);
							}
						}
						else
						{
							flag5 &= this.SetPrepareFightState(gmfRole, ixuisprite, ixuilabel, ixuilabel3);
						}
						bool flag6 = this._GuildDoc.Position != GuildPosition.GPOS_LEADER && this._GuildDoc.Position != GuildPosition.GPOS_VICELEADER;
						if (flag6)
						{
							flag5 = false;
						}
						else
						{
							bool flag7 = this._GuildDoc.Position == GuildPosition.GPOS_VICELEADER;
							if (flag7)
							{
								bool flag8 = gmfRole.guildpos == 0 || gmfRole.guildpos == 1;
								if (flag8)
								{
									flag5 = false;
								}
							}
						}
						bool flag9 = gmfRole.roleID == XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID;
						if (flag9)
						{
							flag5 = false;
						}
						bool flag10 = this._Doc.MyReadyType == XGuildArenaBattleDocument.ReadyType.Observer;
						if (flag10)
						{
							flag5 = false;
						}
						ixuisprite2.gameObject.SetActive(flag5);
					}
				}
			}
		}

		// Token: 0x0600F1E5 RID: 61925 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		protected virtual void SetupOtherMemberInfo(Transform t, GmfRole role)
		{
		}

		// Token: 0x0600F1E6 RID: 61926 RVA: 0x00358E1A File Offset: 0x0035701A
		private void OnRemove(IXUISprite button)
		{
			this.needRemoveID = button.ID;
			XSingleton<UiUtility>.singleton.ShowModalDialog(XStringDefineProxy.GetString("GUILD_ARENA_KICK"), XStringDefineProxy.GetString(XStringDefine.COMMON_OK), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this.OnRemoveQuery));
		}

		// Token: 0x0600F1E7 RID: 61927 RVA: 0x00358E5C File Offset: 0x0035705C
		private bool OnRemoveQuery(IXUIButton btn)
		{
			DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(false, true);
			bool flag = this.needRemoveID > 0UL;
			if (flag)
			{
				this._Doc.ReadyReq(this.needRemoveID, GMFReadyType.GMF_READY_KICK);
			}
			this.needRemoveID = 0UL;
			return true;
		}

		// Token: 0x0600F1E8 RID: 61928 RVA: 0x00358EA8 File Offset: 0x003570A8
		private bool SetPrepareFightState(GmfRole roleInfo, IXUISprite sprite, IXUILabel rank, IXUILabel name)
		{
			rank.gameObject.SetActive(true);
			sprite.gameObject.SetActive(false);
			Color color = Color.white;
			bool flag = roleInfo.roleID == XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID;
			if (flag)
			{
				color = Color.green;
			}
			name.SetColor(color);
			return true;
		}

		// Token: 0x0600F1E9 RID: 61929 RVA: 0x00358F08 File Offset: 0x00357108
		private bool SetMatchFightState(GmfRole roleInfo, IXUISprite sprite, IXUILabel rank, IXUILabel name, IXUILabel fight)
		{
			bool result = true;
			Color color = Color.white;
			bool flag = roleInfo.roleID == XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID;
			if (flag)
			{
				color = Color.green;
			}
			switch (roleInfo.state)
			{
			case GuildMatchFightState.GUILD_MF_WAITING:
			{
				sprite.gameObject.SetActive(false);
				rank.gameObject.SetActive(true);
				bool flag2 = this._GuildDoc.Position != GuildPosition.GPOS_LEADER && this._GuildDoc.Position != GuildPosition.GPOS_VICELEADER;
				result = !flag2;
				break;
			}
			case GuildMatchFightState.GUILD_MF_FIGHTING:
			{
				sprite.gameObject.SetActive(true);
				rank.gameObject.SetActive(false);
				bool flag3 = this.mIndex == 2;
				string sprite2;
				if (flag3)
				{
					sprite2 = "guildpvp_icon_4";
					color = new Color(0.92f, 0.23f, 0.23f);
				}
				else
				{
					sprite2 = "guildpvp_icon_3";
					color = new Color(0f, 0.658f, 1f);
				}
				sprite.SetSprite(sprite2);
				result = false;
				break;
			}
			case GuildMatchFightState.GUILD_MF_FAILED:
			{
				sprite.gameObject.SetActive(true);
				rank.gameObject.SetActive(false);
				string sprite2 = "guildpvp_icon_0";
				sprite.SetSprite(sprite2);
				color = Color.white;
				result = false;
				break;
			}
			}
			rank.SetColor(color);
			name.SetColor(color);
			fight.SetColor(color);
			return result;
		}

		// Token: 0x0600F1EA RID: 61930 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		public void OnUpdate()
		{
		}

		// Token: 0x0600F1EB RID: 61931 RVA: 0x0035908C File Offset: 0x0035728C
		public void SetActive(bool active)
		{
			bool flag = this.transform != null;
			if (flag)
			{
				this.transform.gameObject.SetActive(active);
			}
		}

		// Token: 0x0600F1EC RID: 61932 RVA: 0x003590BC File Offset: 0x003572BC
		public bool IsActive()
		{
			return this.transform != null && this.transform.gameObject.activeSelf;
		}

		// Token: 0x0600F1ED RID: 61933 RVA: 0x003590F0 File Offset: 0x003572F0
		public void Recycle()
		{
			bool flag = this.mRoles != null;
			if (flag)
			{
				this.mRoles.Clear();
				this.mRoles = null;
			}
		}

		// Token: 0x04006770 RID: 26480
		private Transform transform;

		// Token: 0x04006771 RID: 26481
		private IXUIWrapContent m_WrapContent;

		// Token: 0x04006772 RID: 26482
		private IXUIScrollView m_ScrollView;

		// Token: 0x04006773 RID: 26483
		private IXUILabelSymbol m_GuildName;

		// Token: 0x04006774 RID: 26484
		private XGuildArenaBattleDocument _Doc;

		// Token: 0x04006775 RID: 26485
		private XGuildDocument _GuildDoc;

		// Token: 0x04006776 RID: 26486
		private List<GmfRole> mRoles;

		// Token: 0x04006777 RID: 26487
		private int mIndex = 1;

		// Token: 0x04006778 RID: 26488
		private bool isSelfGuild = false;

		// Token: 0x04006779 RID: 26489
		private ulong needRemoveID;
	}
}
